@extends("admin.layout.layout")
@section("content")
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <input type="hidden" name="userid" value="{{$user->user_id}}">
                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>用户名</label>
                        <div class="layui-input-inline">
                            <input type="text" id="L_username" name="username" value="{{$user->user_name}}"  readonly="readonly" autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_pass" class="layui-form-label">
                            密码</label>
                        <div class="layui-input-inline">
                            <input type="password" id="L_pass" name="pass"   autocomplete="off" class="layui-input"></div>
                        <div class="layui-form-mid layui-word-aux">6到12个字符</div></div>
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label">
                            确认密码</label>
                        <div class="layui-input-inline">
                            <input type="password" id="L_repass" name="repass"   autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label">
                            <span class="x-red">*</span>所属角色</label>
                        <div class="layui-input-inline" style="width:70%">
                                @foreach($role as $v)

                                    <input name="roleid" @if(in_array($v->id,$own_roleid)) checked @endif lay-skin="primary" type="checkbox" title="{{$v->role_name}}" value="{{$v->id}}">
                                @endforeach
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="add" lay-submit="">增加</button></div>
                </form>
            </div>
        </div>
        <script>layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;
                //监听提交
                form.on('submit(add)',
                function(data) {
                    var roleid=[];
                    $("input[name='roleid']:checked").each(function(i){
                        roleid[i] = $(this).val();
                    });
                    $.ajax({
                        url: '/admin/user/'+data.field.userid,
                        type: 'PUT',
                        data:{
                            '_token':'{{csrf_token()}}'
                            ,'user_id':data.field.userid
                            ,'user_pass':data.field.pass
                            ,'user_pass_confirmation':data.field.repass
                            ,'roleid':roleid
                        },
                        dataType:'json',
                        success: function(res) {
                            if(res.status == 0){
                                //发异步，把数据提交给php
                                layer.alert(res.message, {
                                        icon: 6
                                    },
                                    function() {
                                        //关闭当前frame
                                        xadmin.close();
                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                    });
                            }else {
                                layer.msg(res.data[0]);
                            }
                        }
                    });
                    return false;
                });

            });</script>
@endsection